


import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hktk_app/util/view_util.dart';

class VideoGuide extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    //   createState
    return _VideoGuideState();
  }

}

class _VideoGuideState extends State<VideoGuide>{
  late int _current=0;
  final CarouselSliderController _controller = CarouselSliderController();
  final List<Map<String,dynamic>> imgList=[{
    "key":0,
    "url":"images/my/操作2.png"
  },{
    "key":1,
    "url":"images/my/操作3.png"
  },{
    "key":2,
    "url":"images/my/操作4.png"
  }];
  @override
  Widget build(BuildContext context) {
    // 
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(

        child: Container(
          decoration: BoxDecoration(borderRadius: BorderRadius.circular(16)),
          child: Stack(
            children: [

              CarouselSlider(
                  items: imgList.map((e){
                    return ClipRRect(
                      borderRadius: BorderRadius.circular(16),
                      child: Image.asset(
                        e["url"],

                        width: 0.8.sw,
                        height: 0.8.sh,
                        fit: BoxFit.fill,
                      ),
                    );
                  }).toList(),
                  carouselController: _controller,
                  options: CarouselOptions(
                    height: 0.8.sh,
                    autoPlay: true,
                    viewportFraction: 1.0,
                    onPageChanged: (index, reason) {
                      // 页面切换回调
                      setState(() {
                        _current = index;
                      });
                    },
                  )),
              Positioned(
                bottom: 21,
                left: 0,
                right: 0,
                child: _indicator(),
              ),
            ],
          ),
        ),
      ),
    );
  }
  _indicator() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: imgList.map((entry) {
        return GestureDetector(
          onTap: () {
            _controller.animateToPage(entry["key"]);
          },
          child: Container(
            width: 12,
            height: 12,
            // 设置两个组件之间的间距，horizontal是左右，注意：组件左右两边都生效
            margin: EdgeInsets.symmetric(horizontal: 6),
            decoration: BoxDecoration(
              color: _current == entry["key"] ? colorYellow1 : colorWhite1,
              shape: BoxShape.circle,
            ),
          ),
        );
      }).toList(),
    );
  }
}